home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  15.0 KB  |  435 lines

  1. /*****************************************************************************
  2.   FILE           : ui_event.c
  3.   SHORTNAME      : event.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : event handler for all graphic windows. This handler only 
  7.                    reacts on mouse and window events. A separate handler of 
  8.                    map events is defined as well.
  9.   NOTES          :
  10.  
  11.   AUTHOR         : Tilman Sommer
  12.   DATE           : 15.5.1990
  13.  
  14.   CHANGED BY     : Michael Vogt, Guenter Mamier
  15.   IDENTIFICATION : @(#)ui_event.c    1.11 3/2/94
  16.   SCCS VERSION   : 1.11 
  17.   LAST CHANGE    : 3/2/94  
  18.  
  19.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  20.              
  21. ******************************************************************************/
  22.  
  23.  
  24. #include <X11/X.h>
  25.  
  26. #include "ui.h"
  27.  
  28. #include "glob_typ.h"    /*  Kernel constant and type definitions  */
  29. #include "kr_ui.h"    /*  Kernel interface functions    */
  30.  
  31. #include "ui_xGraphic.h"
  32. #include "ui_status.h"
  33. #include "ui_infoP.h"
  34. #include "ui_netUpdate.h"
  35. #include "ui_selection.h" 
  36. #include "ui_utilP.h"
  37. #include "ui_display.h"
  38. #include "ui_action.h"    /* move, copy */
  39. #include "ui_key.h"       /* ui_key_popMenu() */
  40. #include "ui_confirmer.h"
  41. #include "ui_mainP.h"
  42. #include "ui_colEdit.h"
  43. #include "ui_color.h"
  44. #include "ui_info.h"
  45.  
  46. #include "ui_event.ph"
  47.  
  48.  
  49. /*****************************************************************************
  50.   FUNCTION : ui_can_MapEventProc
  51.  
  52.   PURPOSE  : notifies all map/unmap events
  53.   RETURNS  : void
  54.   NOTES    : sets the component flags (bit 0) in the display structure 
  55.              indicating, whether drawing in this display is neccessary 
  56.  
  57.   UPDATE   : 20.9.1990
  58. ******************************************************************************/
  59.  
  60. void ui_can_MapEventProc (Widget w,  struct Ui_DisplayType *displayPtr, 
  61.     XEvent    *event)
  62.  
  63. {
  64.  
  65.     switch (event->type) {
  66.       case MapNotify:
  67.     ui_utilSetFlag(displayPtr->flags, 1);
  68.     break;
  69.       case UnmapNotify:
  70.     ui_utilResetFlag(displayPtr->flags, 1);
  71.     break;
  72.     }
  73. }
  74.  
  75.  
  76. /*****************************************************************************
  77.   FUNCTION : ui_mw_eventProc
  78.  
  79.   PURPOSE  : handles all events caused by working in the canvas subwindow
  80.   RETURNS  : void    lot of sideeffects
  81.   NOTES    : This is the main event handler for all pointer (mouse) events 
  82.              occurring in the canvas pixwin subwindow.
  83.          Each accepted event forces an action and also a feedback to the 
  84.          user. This feedback can be:
  85.          - the cursor changes
  86.          - a message will occur, what's going on
  87.          - the position messages (status) below the canvas will be updated
  88.          - a side effect will occur (i.e. update of the unit-panel)
  89.          The mouse cursor must be in the window !!
  90.          * Click down, dragg and release left mouse button will select all
  91.          units in a rectangle area.             
  92.  
  93.   UPDATE   :
  94. *****************************************************************************/
  95.  
  96. void ui_mw_eventProc (Widget w, struct Ui_DisplayType *displayPtr,
  97.     XEvent    *event)
  98.  
  99. {
  100.     int        unitNo;
  101.     FlintType  weight;        /* holds temporary the  weight of a link */
  102.    
  103. /* ------------------------------------------------------------------------ */
  104. /* ------------------------------------------------------------------------ */
  105.     switch (event->type) {
  106. /* ------------------------------------------------------------------------ */
  107. /* ------------------------------------------------------------------------ */
  108.       case ButtonPress:
  109.     if (displayPtr->frozen) return; /* don't accept this event here */
  110.     ui_pixPosMouse.x = (int) event->xbutton.x;
  111.     ui_pixPosMouse.y = (int) event->xbutton.y;
  112.     ui_gridPosMouse  = ui_utilPixToGrid(displayPtr, ui_pixPosMouse);
  113.     ui_unselectFlg   = event->xbutton.state BIT_AND ShiftMask;
  114. /* ------------------------------------------------------------------------ */
  115.     switch (event->xbutton.button) {
  116. /* ------------------------------------------------------------------------ */
  117.       case 1:
  118.         /* LEFT MOUSE BUTTON PRESSED */
  119.         if (event->xbutton.state BIT_AND ControlMask) {
  120.         ui_key_popMenu(displayPtr);
  121.         /* ui_confirmOk("Menu"); */
  122.         break;
  123.         }
  124.         if (NOT ui_outlineActive) {
  125.         ui_leftButton   = TRUE;  
  126.         /* feedback to user: change cursor */
  127.         /* store this position for later use */
  128.         /* draw a initial box and set the flag */
  129.         ui_selGridPos1   = ui_gridPosMouse;
  130.         ui_selPixPos1    = ui_pixPosMouse;
  131.         ui_selPixPosBox  = ui_pixPosMouse;
  132.         
  133.         XSetFunction(ui_display, ui_gc, GXinvert);
  134.         XSetBackground(ui_display, ui_gc, ui_backgroundColor); /* back */
  135.         XSetForeground(ui_display, ui_gc, ui_textColor); /* text */
  136.         if (ui_col_colorDisplay)
  137.             XSetPlaneMask(ui_display, ui_gc, 
  138.                   ui_textColor BIT_XOR ui_backgroundColor);
  139.         ui_xDrawBox(ui_display, displayPtr->drawable, 
  140.                 ui_gc, ui_selPixPos1, ui_selPixPosBox);
  141.         if (ui_col_colorDisplay)
  142.             XSetPlaneMask(ui_display, ui_gc, AllPlanes);
  143.         ui_pixBoxDrawnFlg = TRUE; /* a box is drawn */
  144.         }
  145.         break;
  146. /* ------------------------------------------------------------------------ */
  147.       case 2:
  148.         /* MIDDLE MOUSE BUTTON PRESSED */
  149.         if (not ui_outlineActive) {
  150.         ui_middleButton      = TRUE;
  151.         ui_link_sourceUnitNo = 
  152.             krui_getUnitNoNearPosition(&ui_gridPosMouse, 
  153.                            displayPtr->subNetNo,
  154.                            9, 
  155.                            displayPtr->gridSize);
  156.         }
  157.         break;
  158. /* ------------------------------------------------------------------------ */
  159.       case 3:
  160.         /* RIGHT MOUSE BUTTON PRESSED */
  161.         break;
  162.     }
  163.     break;
  164. /* ------------------------------------------------------------------------ */
  165. /* ------------------------------------------------------------------------ */
  166.       case ButtonRelease:
  167.     if (displayPtr->frozen) return; /* don't accept this event here */
  168.     ui_pixPosMouse.x = (int) event->xbutton.x;
  169.     ui_pixPosMouse.y = (int) event->xbutton.y;
  170.     ui_gridPosMouse  = ui_utilPixToGrid(displayPtr, ui_pixPosMouse);
  171.     ui_unselectFlg   = event->xbutton.state BIT_AND ShiftMask;
  172. /* ------------------------------------------------------------------------ */
  173.     switch (event->xbutton.button) {
  174. /* ------------------------------------------------------------------------ */
  175.       case 1:
  176.         /* LEFT MOUSE BUTTON RELEASED */
  177.         if (ui_outlineActive) {
  178.         struct PosType offset;
  179.         /* erase outline */
  180.         offset.x = ui_gridPosMouse.x - ui_targetUnit.gridPos.x;
  181.         offset.y = ui_gridPosMouse.y - ui_targetUnit.gridPos.y;
  182.         ui_sel_drawBoxes(displayPtr, UI_GLOBAL, offset);
  183.         ui_outlineActive = FALSE;
  184.         ui_key_eventPos  = ui_gridPosMouse;
  185.         if (ui_key_action == UI_ACTION_MOVE) {
  186.             ui_printMessage("Units Move ...");
  187.             ui_action_unitsMove();
  188.         } else {
  189.             ui_printMessage("Units Copy ...");
  190.             ui_action_unitsCopy();
  191.         }
  192.         ui_printMessage(">");
  193.         ui_key_currentState = ui_key_returnUnitState;
  194.         } else {
  195.         ui_leftButton   = FALSE;
  196.         
  197.         /* erase box, store position and normalize */
  198.         /* normalize: gridPos1 will be the upper left corner */
  199.         
  200.         if (ui_pixBoxDrawnFlg) {
  201.             XSetFunction(ui_display, ui_gc, GXinvert);
  202.             XSetBackground(ui_display, ui_gc, ui_backgroundColor); /* back */
  203.             XSetForeground(ui_display, ui_gc, ui_textColor);
  204.             if (ui_col_colorDisplay)
  205.             XSetPlaneMask(ui_display, ui_gc, 
  206.                       ui_textColor BIT_XOR ui_backgroundColor);
  207.             ui_xDrawBox(ui_display, displayPtr->drawable, ui_gc, 
  208.                 ui_selPixPos1, ui_selPixPosBox);
  209.             if (ui_col_colorDisplay)
  210.             XSetPlaneMask(ui_display, ui_gc, AllPlanes);
  211.             ui_pixBoxDrawnFlg = FALSE;
  212.         }
  213.         
  214.         ui_selGridPos2 = ui_gridPosMouse;
  215.         
  216.         ui_utilNormalizeRect(&ui_selGridPos1, &ui_selGridPos2);
  217.         
  218.         /* depending of the shift state: select or unselect */
  219.         
  220.         if (ui_unselectFlg)  /* unselect */
  221.             
  222.             if ((NOT (krui_getUnitNoNearPosition(&ui_selGridPos1,
  223.                              displayPtr->subNetNo,
  224.                              9, 
  225.                              displayPtr->gridSize) > 0)) AND
  226.             (ui_utilAreEqualPositions(ui_selGridPos1, ui_selGridPos2))) { 
  227.             /* user clicked a empty position -> select all */
  228.             /* ui_sel_selectAll(...) not implemented */
  229.             ui_stat_displayStatus(ui_gridPosMouse);
  230.             } else 
  231.             if (ui_utilAreEqualPositions(ui_selGridPos1,
  232.                              ui_selGridPos2)) {
  233.                 int unitNo;
  234.                 if ((unitNo = 
  235.                 krui_getUnitNoNearPosition(&ui_selGridPos1,
  236.                                displayPtr->subNetNo,
  237.                                9, 
  238.                                displayPtr->gridSize)) > 0) {
  239.                 krui_getUnitPosition(unitNo, &ui_selGridPos1);
  240.                 ui_sel_unselectOne(displayPtr, UI_GLOBAL,
  241.                            unitNo, ui_selGridPos1);
  242.                 }
  243.             } else
  244.                 ui_sel_unselectRect(displayPtr, UI_GLOBAL,
  245.                         ui_selGridPos1, ui_selGridPos2); 
  246.         else  /* select */
  247.             if (ui_utilAreEqualPositions(ui_selGridPos1,
  248.                          ui_selGridPos2)) {
  249.             int unitNo;
  250.             if ((unitNo = 
  251.                  krui_getUnitNoNearPosition(&ui_selGridPos1,
  252.                             displayPtr->subNetNo,
  253.                             9, 
  254.                             displayPtr->gridSize)) > 0) {
  255.                 krui_getUnitPosition(unitNo, &ui_selGridPos1);
  256.                 ui_sel_selectOne(displayPtr, UI_GLOBAL,
  257.                          unitNo, ui_selGridPos1);
  258.             }
  259.             } else
  260.             ui_sel_selectRect(displayPtr, UI_GLOBAL,
  261.                       ui_selGridPos1, ui_selGridPos2); 
  262.         
  263.         ui_leftButton = FALSE;  /* signal: end of operation */
  264.         }
  265.         break;
  266. /* ------------------------------------------------------------------------ */
  267.       case 2:
  268.         /* MIDDLE MOUSE BUTTON RELEASED */
  269.         if ((NOT ui_outlineActive) AND ui_middleButton AND ui_infoIsCreated) {
  270.         int targetUnitNo;
  271.  
  272.         if ((targetUnitNo = 
  273.              krui_getUnitNoNearPosition(&ui_gridPosMouse,
  274.                         displayPtr->subNetNo,
  275.                         9, 
  276.                         displayPtr->gridSize)) > 0) { 
  277.             /* a target unit exist */
  278.             if (ui_link_sourceUnitNo == 0)
  279.             /* if pressed on an empty position then use
  280.                old SOURCE instead ! */
  281.             ui_link_sourceUnitNo = ui_sourceUnit.no;
  282.             /* show data in the unit info panel */
  283.             ui_info_showSelectedUnit(targetUnitNo);
  284.             krui_setCurrentUnit(targetUnitNo);
  285.             if (krui_isConnected(ui_link_sourceUnitNo)) { 
  286.             /* if the source unit exists and already connected 
  287.                then show all data of the Link */
  288.             weight = krui_getLinkWeight();
  289.             ui_info_showPredOfTargetUnit(ui_link_sourceUnitNo, 
  290.                              weight);
  291.             }
  292.         } else { /* released on empty position */
  293.             if (ui_link_sourceUnitNo != 0) {
  294.             /* pressed on a unit position */
  295.             /* try to display the connection source -> TARGET */
  296.             krui_setCurrentUnit(ui_targetUnit.no);
  297.             if (krui_areConnected(ui_link_sourceUnitNo,
  298.                           ui_targetUnit.no,
  299.                           &weight)) { 
  300.                 /* if the source unit exists and already connected 
  301.                    then show all data of the Link */
  302.                 ui_info_showPredOfTargetUnit(ui_link_sourceUnitNo,
  303.                              weight);
  304.             }
  305.             }
  306.         }
  307.         }
  308.         ui_middleButton = FALSE;
  309.         break;
  310. /* ------------------------------------------------------------------------ */
  311.       case 3:
  312.         /* RIGHT MOUSE BUTTON RELEASED */
  313.         if (NOT ui_outlineActive) {
  314.         struct PosType  gridPos;
  315.         if ((unitNo = 
  316.             krui_getUnitNoNearPosition(&ui_gridPosMouse,
  317.                            displayPtr->subNetNo,
  318.                            9, 
  319.                            displayPtr->gridSize)) > 0) {
  320.             krui_getUnitPosition(unitNo, &gridPos);
  321.             ui_sel_unselectOne(displayPtr, UI_GLOBAL, unitNo, gridPos); 
  322.             /* unselectOne gives not a message by itsself ! */
  323.             ui_sel_msgNumber(); 
  324.         } else { /* user clicked on an empty position */
  325.             ui_sel_unselectAll(displayPtr, UI_GLOBAL); 
  326.             ui_stat_displayStatus(ui_gridPosMouse);
  327.         }
  328.         }
  329.         break;
  330. /* ------------------------------------------------------------------------ */
  331.     }
  332.     break;
  333. /* ------------------------------------------------------------------------ */
  334. /* ------------------------------------------------------------------------ */
  335.       case MotionNotify:
  336.     if (displayPtr->frozen) return; /* don't accept this event here */
  337.  
  338.     ui_pixPosMouse.x = (int) event->xbutton.x;
  339.     ui_pixPosMouse.y = (int) event->xbutton.y;
  340.     ui_gridPosMouse  = ui_utilPixToGrid(displayPtr, ui_pixPosMouse);
  341.  
  342.     if (ui_utilAreDifferentPositions(ui_gridPosOld, ui_gridPosMouse)) {
  343.         ui_stat_displayStatus(ui_gridPosMouse);
  344.  
  345.         if (ui_outlineActive) {
  346.         struct PosType offset;
  347.         offset.x = ui_gridPosOld.x - ui_targetUnit.gridPos.x;
  348.         offset.y = ui_gridPosOld.y - ui_targetUnit.gridPos.y;
  349.         ui_sel_drawBoxes(displayPtr, UI_GLOBAL, offset);
  350.         offset.x = ui_gridPosMouse.x - ui_targetUnit.gridPos.x;
  351.         offset.y = ui_gridPosMouse.y - ui_targetUnit.gridPos.y;
  352.         ui_sel_drawBoxes(displayPtr, UI_GLOBAL, offset);
  353.         }
  354.     }
  355.  
  356.     if ((NOT ui_outlineActive) AND (event->xmotion.state AND 
  357.                     (Button1Mask | Button2Mask | 
  358.                      Button3Mask))) {
  359.         /* at least one of the three mouse buttons is depressed !  
  360.            ==> MOUSE DRAGG */ 
  361.         
  362.         /* only with left button down */
  363.         if (ui_leftButton) {
  364.         /* draw rubber square on screen while dragging the mouse */
  365.         /* Because two boxes are drawn, don't change the flag
  366.            ui_pixBoxDrawnFlg ! */
  367.         XSetFunction(ui_display, ui_gc, GXinvert);
  368.         XSetBackground(ui_display, ui_gc, ui_backgroundColor); /* back */
  369.         XSetForeground(ui_display, ui_gc, ui_textColor);
  370.         if (ui_col_colorDisplay)
  371.             XSetPlaneMask(ui_display, ui_gc, 
  372.                   ui_textColor BIT_XOR ui_backgroundColor);
  373.         ui_xDrawBox(ui_display, displayPtr->drawable, 
  374.                 ui_gc, ui_selPixPos1, ui_selPixPosBox);
  375.         ui_selPixPosBox = ui_pixPosMouse; 
  376.         ui_xDrawBox(ui_display, displayPtr->drawable, 
  377.                 ui_gc, ui_selPixPos1, ui_selPixPosBox);
  378.         if (ui_col_colorDisplay)
  379.             XSetPlaneMask(ui_display, ui_gc, AllPlanes);
  380.         ui_pixBoxDrawnFlg = TRUE; /* a box is drawn */
  381.         }
  382.     }
  383.     break;
  384. /* ------------------------------------------------------------------------ */
  385. /* ------------------------------------------------------------------------ */
  386.       case EnterNotify:
  387.     /* mouse cursor moved into canvas subwindow */
  388.     if (displayPtr->frozen) return; /* don't accept this event here */
  389.     ui_pixPosMouse.x = (int) event->xbutton.x;
  390.     ui_pixPosMouse.y = (int) event->xbutton.y;
  391.     ui_gridPosMouse  = ui_utilPixToGrid(displayPtr, ui_pixPosMouse);
  392.     ui_stat_displayStatus(ui_gridPosMouse);
  393.     ui_currentDisplay = displayPtr;
  394.     if (ui_outlineActive) {
  395.         struct PosType offset;
  396.         offset.x = ui_gridPosMouse.x - ui_targetUnit.gridPos.x;
  397.         offset.y = ui_gridPosMouse.y - ui_targetUnit.gridPos.y;
  398.         ui_sel_drawBoxes(displayPtr, UI_GLOBAL, offset);
  399. #ifdef DEBUG
  400.         XFlush(ui_display);
  401. #endif
  402.     }    
  403.     break;
  404. /* ------------------------------------------------------------------------ */
  405. /* ------------------------------------------------------------------------ */
  406.       case LeaveNotify: 
  407.     /* mouse cursor moved out of canvas subwindow */
  408.     if (displayPtr->frozen) return; /* don't accept this event here */
  409.     if (ui_outlineActive) {
  410.         struct PosType offset;
  411.         offset.x = ui_gridPosOld.x - ui_targetUnit.gridPos.x;
  412.         offset.y = ui_gridPosOld.y - ui_targetUnit.gridPos.y;
  413.         ui_sel_drawBoxes(displayPtr, UI_GLOBAL, offset);
  414. #ifdef DEBUG
  415.         XFlush(ui_display);
  416. #endif
  417.     }
  418.     break;
  419. /* ------------------------------------------------------------------------ */
  420. /* ------------------------------------------------------------------------ */
  421.     }
  422. /* ------------------------------------------------------------------------ */
  423. /* ------------------------------------------------------------------------ */
  424.     
  425.     ui_pixPosOld  = ui_pixPosMouse; /* store pos for the next call */
  426.     ui_gridPosOld = ui_gridPosMouse;
  427. }
  428.  
  429.  
  430.  
  431.  
  432.  
  433. /* end of file */
  434. /* lines: 479 */
  435.